﻿using Smart.Utils.Lib;
using System;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace Smart.ERP.PMQLNS
{
    public class C_PhanCong_Dept
    {
        private bool m_Ca1;
        private bool m_Ca2;
        private bool m_Ca3;
        private string m_DeptID;
        private bool m_HC1;
        private bool m_HC2;

        public C_PhanCong_Dept()
        {
            this.m_DeptID = "";
            this.m_Ca1 = true;
            this.m_Ca2 = true;
            this.m_Ca3 = true;
            this.m_HC1 = true;
            this.m_HC2 = true;
        }

        public C_PhanCong_Dept(string DeptID, bool Ca1, bool Ca2, bool Ca3, bool HC1, bool HC2)
        {
            this.m_DeptID = DeptID;
            this.m_Ca1 = Ca1;
            this.m_Ca2 = Ca2;
            this.m_Ca3 = Ca3;
            this.m_HC1 = HC1;
            this.m_HC2 = HC2;
        }

        public void AddCombo(System.Windows.Forms.ComboBox combo)
        {
            this.AddCombo(combo, this.LookUp());
        }

        public void AddCombo(System.Windows.Forms.ComboBox combo, DataTable dt)
        {
            MyLib.TableToComboBox(combo, dt, "ID", "Name");
        }

        public void AddComboAll(System.Windows.Forms.ComboBox combo)
        {
            this.AddComboAll(combo, "(Tất cả)");
        }

        public void AddComboAll(System.Windows.Forms.ComboBox combo, string text)
        {
            DataTable table = new DataTable();
            table = this.LookUp();
            DataRow row = table.NewRow();
            row["ID"] = "All";
            row["Name"] = text;
            table.Rows.InsertAt(row, 0);
            MyLib.TableToComboBox(combo, table, "ID", "Name");
        }

        public void AddComboDefault(System.Windows.Forms.ComboBox combo)
        {
            this.AddComboAll(combo, "(Mặc định)");
        }

        public int Count()
        {
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            if (helper.Open() != "OK")
            {
                return 0;
            }
            int num = this.Count(helper.Connection);
            helper.Close();
            return num;
        }

        public int Count(SqlConnection myConnection)
        {
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            return helper.ExecuteScalar(myConnection, "C_PhanCong_Dept_Count", 0);
        }

        public int Count(SqlTransaction myTransaction)
        {
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            return helper.ExecuteScalar(myTransaction, "C_PhanCong_Dept_Count", 0);
        }

        public string CreateKey()
        {
            return this.CreateKey("");
        }

        public string CreateKey(SqlTransaction myTransaction)
        {
            return SqlHelper.GenCode(myTransaction, "");
        }

        public string CreateKey(string key)
        {
            return SqlHelper.GenCode(key);
        }

        public string CreateKey(SqlTransaction myTransaction, string key)
        {
            return SqlHelper.GenCode(myTransaction, key);
        }

        public bool Delete()
        {
            return this.Delete(this.m_DeptID);
        }

        public bool Delete(SqlConnection myConnection)
        {
            return this.Delete(myConnection, this.m_DeptID);
        }

        public bool Delete(SqlTransaction myTransaction)
        {
            return this.Delete(myTransaction, this.m_DeptID);
        }

        public bool Delete(string DeptID)
        {
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            if ((helper.Open() == "OK") && this.Delete(helper.Connection, DeptID))
            {
                helper.Close();
                return true;
            }
            return false;
        }

        public bool Delete(SqlConnection myConnection, string DeptID)
        {
            string[] myParams = new string[] { "@DeptID" };
            object[] myValues = new object[] { DeptID };
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            return (helper.ExecuteNonQuery(myConnection, "C_PhanCong_Dept_Delete", myParams, myValues) == "OK");
        }

        public bool Delete(SqlTransaction myTransaction, string DeptID)
        {
            string[] myParams = new string[] { "@DeptID" };
            object[] myValues = new object[] { DeptID };
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            return (helper.ExecuteNonQuery(myTransaction, "C_PhanCong_Dept_Delete", myParams, myValues) == "OK");
        }

        private void DispError(object sender, SqlHelperException e)
        {
            XtraMessageBox.Show(e.Message, "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }

        public bool Exist()
        {
            return this.Exist(this.m_DeptID);
        }

        public bool Exist(SqlTransaction myTransaction)
        {
            return this.Exist(myTransaction, this.m_DeptID);
        }

        public bool Exist(string DeptID)
        {
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            if ((helper.Open() == "OK") && this.Exist(helper.Connection, DeptID))
            {
                helper.Close();
                return true;
            }
            return false;
        }

        public bool Exist(SqlConnection myConnection, string DeptID)
        {
            bool hasRows = false;
            string[] myParams = new string[] { "@DeptID" };
            object[] myValues = new object[] { DeptID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myConnection, "C_PhanCong_Dept_Get", myParams, myValues);
            if (reader != null)
            {
                hasRows = reader.HasRows;
                reader.Close();
                return hasRows;
            }
            helper.Close();
            if (MyParamaters.IsShowWarning)
            {
                XtraMessageBox.Show(helper.Result, "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            return hasRows;
        }

        public bool Exist(SqlTransaction myTransaction, string DeptID)
        {
            bool hasRows = false;
            string[] myParams = new string[] { "@DeptID" };
            object[] myValues = new object[] { DeptID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myTransaction, "C_PhanCong_Dept_Get", myParams, myValues);
            if (reader != null)
            {
                hasRows = reader.HasRows;
                reader.Close();
                return hasRows;
            }
            helper.RollBack(myTransaction);
            if (MyParamaters.IsShowWarning)
            {
                XtraMessageBox.Show(helper.Result, "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            return hasRows;
        }

        public bool Get()
        {
            return this.Get(this.m_DeptID);
        }

        public bool Get(SqlConnection myConnection)
        {
            return this.Get(myConnection, this.m_DeptID);
        }

        public bool Get(SqlTransaction myTransaction)
        {
            return this.Get(myTransaction, this.m_DeptID);
        }

        public bool Get(string DeptID)
        {
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            if ((helper.Open() == "OK") && this.Get(helper.Connection, DeptID))
            {
                helper.Close();
                return true;
            }
            return false;
        }

        public bool Get(SqlConnection myConnection, string DeptID)
        {
            bool flag = false;
            string[] myParams = new string[] { "@DeptID" };
            object[] myValues = new object[] { DeptID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myConnection, "C_PhanCong_Dept_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_DeptID = Convert.ToString(reader["DeptID"]);
                    this.m_Ca1 = Convert.ToBoolean(reader["Ca1"]);
                    this.m_Ca2 = Convert.ToBoolean(reader["Ca2"]);
                    this.m_Ca3 = Convert.ToBoolean(reader["Ca3"]);
                    this.m_HC1 = Convert.ToBoolean(reader["HC1"]);
                    this.m_HC2 = Convert.ToBoolean(reader["HC2"]);
                    flag = true;
                }
                reader.Close();
                reader = null;
                return flag;
            }
            helper.Close();
            if (MyParamaters.IsShowWarning)
            {
                XtraMessageBox.Show(helper.Result, "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            return flag;
        }

        public bool Get(SqlTransaction myTransaction, string DeptID)
        {
            bool flag = false;
            string[] myParams = new string[] { "@DeptID" };
            object[] myValues = new object[] { DeptID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myTransaction, "C_PhanCong_Dept_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_DeptID = Convert.ToString(reader["DeptID"]);
                    this.m_Ca1 = Convert.ToBoolean(reader["Ca1"]);
                    this.m_Ca2 = Convert.ToBoolean(reader["Ca2"]);
                    this.m_Ca3 = Convert.ToBoolean(reader["Ca3"]);
                    this.m_HC1 = Convert.ToBoolean(reader["HC1"]);
                    this.m_HC2 = Convert.ToBoolean(reader["HC2"]);
                    flag = true;
                }
                reader.Close();
                reader = null;
                return flag;
            }
            helper.RollBack(myTransaction);
            if (MyParamaters.IsShowWarning)
            {
                XtraMessageBox.Show(helper.Result, "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            return flag;
        }

        public DataTable GetList()
        {
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            return helper.ExecuteDataTable("C_PhanCong_Dept_GetList");
        }

        public DataTable GetList(SqlConnection myConnection)
        {
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            return helper.ExecuteDataTable(myConnection, "C_PhanCong_Dept_GetList");
        }

        public DataTable GetList(SqlTransaction myTransaction)
        {
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            return helper.ExecuteDataTable(myTransaction, "C_PhanCong_Dept_GetList");
        }

        public bool Insert()
        {
            return this.Insert(this.m_DeptID, this.m_Ca1, this.m_Ca2, this.m_Ca3, this.m_HC1, this.m_HC2);
        }

        public bool Insert(SqlConnection myConnection)
        {
            return this.Insert(myConnection, this.m_DeptID, this.m_Ca1, this.m_Ca2, this.m_Ca3, this.m_HC1, this.m_HC2);
        }

        public bool Insert(SqlTransaction myTransaction)
        {
            return this.Insert(myTransaction, this.m_DeptID, this.m_Ca1, this.m_Ca2, this.m_Ca3, this.m_HC1, this.m_HC2);
        }

        public bool Insert(string DeptID, bool Ca1, bool Ca2, bool Ca3, bool HC1, bool HC2)
        {
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            if ((helper.Open() == "OK") && this.Insert(helper.Connection, DeptID, Ca1, Ca2, Ca3, HC1, HC2))
            {
                helper.Close();
                return true;
            }
            return false;
        }

        public bool Insert(SqlConnection myConnection, string DeptID, bool Ca1, bool Ca2, bool Ca3, bool HC1, bool HC2)
        {
            string[] myParams = new string[] { "@DeptID", "@Ca1", "@Ca2", "@Ca3", "@HC1", "@HC2" };
            object[] myValues = new object[] { DeptID, Ca1, Ca2, Ca3, HC1, HC2 };
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            return (helper.ExecuteNonQuery(myConnection, "C_PhanCong_Dept_Insert", myParams, myValues) == "OK");
        }

        public bool Insert(SqlTransaction myTransaction, string DeptID, bool Ca1, bool Ca2, bool Ca3, bool HC1, bool HC2)
        {
            string[] myParams = new string[] { "@DeptID", "@Ca1", "@Ca2", "@Ca3", "@HC1", "@HC2" };
            object[] myValues = new object[] { DeptID, Ca1, Ca2, Ca3, HC1, HC2 };
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            return (helper.ExecuteNonQuery(myTransaction, "C_PhanCong_Dept_Insert", myParams, myValues) == "OK");
        }

        public DataTable LookUp()
        {
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            return helper.ExecuteDataTable("C_PhanCong_Dept_LookUp");
        }

        public string NewID()
        {
            return this.NewID("");
        }

        public string NewID(string key)
        {
            return SqlHelper.GenCode("C_PhanCong_Dept", "C_PhanCong_DeptID", key);
        }

        public string NewID(SqlTransaction myTransaction, string key)
        {
            return SqlHelper.GenCode(myTransaction, "C_PhanCong_Dept", "C_PhanCong_DeptID", key);
        }

        public DataTable Search(bool Ca1, bool Ca2, bool Ca3, bool HC1, bool HC2)
        {
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            if (helper.Open() != "OK")
            {
                return null;
            }
            return this.Search(helper.Connection, Ca1, Ca2, Ca3, HC1, HC2);
        }

        public DataTable Search(SqlConnection myConnection, bool Ca1, bool Ca2, bool Ca3, bool HC1, bool HC2)
        {
            string[] myParams = new string[] { "@Ca1", "@Ca2", "@Ca3", "@HC1", "@HC2" };
            object[] myValues = new object[] { "%" + Ca1 + "%", "%" + Ca2 + "%", "%" + Ca3 + "%", "%" + HC1 + "%", "%" + HC2 + "%" };
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            return helper.ExecuteDataTable(myConnection, "C_PhanCong_Dept_Search", myParams, myValues);
        }

        public DataTable Search(SqlTransaction myTransaction, bool Ca1, bool Ca2, bool Ca3, bool HC1, bool HC2)
        {
            string[] myParams = new string[] { "@Ca1", "@Ca2", "@Ca3", "@HC1", "@HC2" };
            object[] myValues = new object[] { "%" + Ca1 + "%", "%" + Ca2 + "%", "%" + Ca3 + "%", "%" + HC1 + "%", "%" + HC2 + "%" };
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            return helper.ExecuteDataTable(myTransaction, "C_PhanCong_Dept_Search", myParams, myValues);
        }

        public void SetData(string DeptID, bool Ca1, bool Ca2, bool Ca3, bool HC1, bool HC2)
        {
            this.m_DeptID = DeptID;
            this.m_Ca1 = Ca1;
            this.m_Ca2 = Ca2;
            this.m_Ca3 = Ca3;
            this.m_HC1 = HC1;
            this.m_HC2 = HC2;
        }

        public bool Update()
        {
            return this.Update(this.m_DeptID, this.m_Ca1, this.m_Ca2, this.m_Ca3, this.m_HC1, this.m_HC2);
        }

        public bool Update(SqlConnection myConnection)
        {
            return this.Update(this.m_DeptID, this.m_Ca1, this.m_Ca2, this.m_Ca3, this.m_HC1, this.m_HC2);
        }

        public bool Update(SqlTransaction myTransaction)
        {
            return this.Update(myTransaction, this.m_DeptID, this.m_Ca1, this.m_Ca2, this.m_Ca3, this.m_HC1, this.m_HC2);
        }

        public bool Update(string DeptID, bool Ca1, bool Ca2, bool Ca3, bool HC1, bool HC2)
        {
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            if ((helper.Open() == "OK") && this.Update(helper.Connection, DeptID, Ca1, Ca2, Ca3, HC1, HC2))
            {
                helper.Close();
                return true;
            }
            return false;
        }

        public bool Update(SqlConnection myConnection, string DeptID, bool Ca1, bool Ca2, bool Ca3, bool HC1, bool HC2)
        {
            string[] myParams = new string[] { "@DeptID", "@Ca1", "@Ca2", "@Ca3", "@HC1", "@HC2" };
            object[] myValues = new object[] { DeptID, Ca1, Ca2, Ca3, HC1, HC2 };
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            return (helper.ExecuteNonQuery(myConnection, "C_PhanCong_Dept_Update", myParams, myValues) == "OK");
        }

        public bool Update(SqlTransaction myTransaction, string DeptID, bool Ca1, bool Ca2, bool Ca3, bool HC1, bool HC2)
        {
            string[] myParams = new string[] { "@DeptID", "@Ca1", "@Ca2", "@Ca3", "@HC1", "@HC2" };
            object[] myValues = new object[] { DeptID, Ca1, Ca2, Ca3, HC1, HC2 };
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            return (helper.ExecuteNonQuery(myTransaction, "C_PhanCong_Dept_Update", myParams, myValues) == "OK");
        }

        public bool UpdateByID()
        {
            return this.UpdateByID(this.m_DeptID, this.m_Ca1, this.m_Ca2, this.m_Ca3, this.m_HC1, this.m_HC2);
        }

        public bool UpdateByID(SqlConnection myConnection)
        {
            return this.UpdateByID(myConnection, this.m_DeptID, this.m_Ca1, this.m_Ca2, this.m_Ca3, this.m_HC1, this.m_HC2);
        }

        public bool UpdateByID(SqlTransaction myTransaction)
        {
            return this.UpdateByID(myTransaction, this.m_DeptID, this.m_Ca1, this.m_Ca2, this.m_Ca3, this.m_HC1, this.m_HC2);
        }

        public bool UpdateByID(string DeptID, bool Ca1, bool Ca2, bool Ca3, bool HC1, bool HC2)
        {
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            if ((helper.Open() == "OK") && this.UpdateByID(helper.Connection, DeptID, Ca1, Ca2, Ca3, HC1, HC2))
            {
                helper.Close();
                return true;
            }
            return false;
        }

        public bool UpdateByID(SqlConnection myConnection, string DeptID, bool Ca1, bool Ca2, bool Ca3, bool HC1, bool HC2)
        {
            string[] myParams = new string[] { "@DeptID", "@Ca1", "@Ca2", "@Ca3", "@HC1", "@HC2" };
            object[] myValues = new object[] { DeptID, Ca1, Ca2, Ca3, HC1, HC2 };
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            return (helper.ExecuteNonQuery(myConnection, "C_PhanCong_Dept_UpdateByID", myParams, myValues) == "OK");
        }

        public bool UpdateByID(SqlTransaction myTransaction, string DeptID, bool Ca1, bool Ca2, bool Ca3, bool HC1, bool HC2)
        {
            string[] myParams = new string[] { "@DeptID", "@Ca1", "@Ca2", "@Ca3", "@HC1", "@HC2" };
            object[] myValues = new object[] { DeptID, Ca1, Ca2, Ca3, HC1, HC2 };
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            return (helper.ExecuteNonQuery(myTransaction, "C_PhanCong_Dept_UpdateByID", myParams, myValues) == "OK");
        }

        public string AssemblyVersion
        {
            get
            {
                return "2.5.0.0";
            }
        }

        [DisplayName("Ca1"), Category("Column")]
        public bool Ca1
        {
            get
            {
                return this.m_Ca1;
            }
            set
            {
                this.m_Ca1 = value;
            }
        }

        [Category("Column"), DisplayName("Ca2")]
        public bool Ca2
        {
            get
            {
                return this.m_Ca2;
            }
            set
            {
                this.m_Ca2 = value;
            }
        }

        [DisplayName("Ca3"), Category("Column")]
        public bool Ca3
        {
            get
            {
                return this.m_Ca3;
            }
            set
            {
                this.m_Ca3 = value;
            }
        }

        public string Copyright
        {
            get
            {
                return "C\x00f4ng Ty Phần Mềm Ho\x00e0n Hảo";
            }
        }

        [DisplayName("DeptID"), Category("Primary Key")]
        public string DeptID
        {
            get
            {
                return this.m_DeptID;
            }
            set
            {
                this.m_DeptID = value;
            }
        }

        [DisplayName("HC1"), Category("Column")]
        public bool HC1
        {
            get
            {
                return this.m_HC1;
            }
            set
            {
                this.m_HC1 = value;
            }
        }

        [Category("Column"), DisplayName("HC2")]
        public bool HC2
        {
            get
            {
                return this.m_HC2;
            }
            set
            {
                this.m_HC2 = value;
            }
        }

        public string Product
        {
            get
            {
                return "Class C_PhanCong_Dept";
            }
        }
    }
}
